import { app } from "db://app-game/core/app";
import { ecs } from "db://app-game/libs/ecs/ECS";
import { Initialize } from "../Initialize";
import { InitializeViewComp } from "../view/InitializeViewComp";
import { UIID } from "../../../common/config/GameUIConfig";

/** 初始化游戏公共资源 */
@ecs.register("InitRes")
export class InitResComp extends ecs.Comp {
  reset() {}
}

/** 加载游戏资源 */
@ecs.register("Initialize")
export class InitResSystem
  extends ecs.ComblockSystem
  implements ecs.IEntityEnterSystem
{
  async entityEnter(e: Initialize): Promise<void> {
    // 完成时打开加载界面
    let node = await app.gui.openAsync(UIID.Initialize);
    if (node) {
      e.add(node.getComponent(InitializeViewComp)!);
      e.remove(InitResComp);
    }
  }

  filter(): ecs.IMatcher {
    return ecs.allOf(InitResComp);
  }
}
